let arr = [3,6,4,9,1]
let k = 3
// arr.sort((a, b) => b - a)
// console.log(arr[k-1])
let len = arr.length - 1
for(let i = len, tmp; i > len - k; i--){
  for(let j = 0; j < i; j++){
    if(arr[j] > arr[j+1]){
      tmp = arr[j]
      arr[j] = arr[j+1]
      arr[j+1] = tmp
    }
  }
}
console.log(arr[len-(k-1)])